package sort;

import java.util.Arrays;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:
 * User:Mr.Du
 * Date:2022/3/8
 * Time:16:11
 */
public class 冒泡排序 {
    public static void main(String[] args) {

        int[] arr = {5,7,3,1,8,9,4,6,2};
        System.out.println("初始化："+ Arrays.toString(arr));
        bubbleSort(arr);
        System.out.println(Arrays.toString(arr));

    }

    private static void bubbleSort(int[] arr) {
        for(int i = 0;i < arr.length;i++){
            for(int j = 0;j < arr.length - i - 1;j++){
                if(arr[j]>arr[j+1]){
                    int tmp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = tmp;
                }
            }
        }
    }

}
